﻿using System.Data;
using Barry.Slide.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace Barry.Slide
{
    public class Migrations:DataMigrationImpl
    {
        public int Create() {
            // Creating table MapRecord
            SchemaBuilder.CreateTable("SlideRecord", table => table
                .ContentPartRecord()
                .Column("Latitude", DbType.Double)
                .Column("Longitude", DbType.Double)
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(SlidePart).Name, cfg => cfg.Attachable());
            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.AlterTable("SlideRecord", 
                table =>
                    table.AddColumn("URLists", DbType.String));
            return 2;
        }

        public int UpdateFrom2()
        {
            SchemaBuilder.AlterTable("SlideRecord",
                                     table => table
                                         .DropColumn("URLists"));
            SchemaBuilder.AlterTable("SlideRecord",
                                     table => table.AddColumn("URLLists", DbType.AnsiString));
            return 3;
        }
     
    }
}